package targetOffer;

public class Test {

    ThreadLocal<A> local = ThreadLocal.withInitial(() -> new A(0));

    public static void main(String[] args) {
        Test t1 = new Test();
        A a = new A(1);
        t1.setLocal(a);
        new Thread(() -> {
            Test t2 = new Test();
            t2.printLocal();
        }).start();
        t1.printLocal();
    }

    public void setLocal(A value) {
        local.set(value);
        local.set(new A(2));
    }

    public A getLocal() {
        return local.get();
    }

    public void printLocal() {
        System.out.println(Thread.currentThread().getName() + ":" + getLocal());
    }
}

class A {
    int value;

    A(int value) {
        this.value = value;
        this.value = value;
    }

    @Override
    public String toString() {
        return value + "";
    }
}